﻿<Controls:MetroWindow  x:Class="iBackupExplorer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        Title="iBackup Explorer" Height="350" Width="525" SaveWindowPosition="True" 
        WindowStartupLocation="CenterScreen" ShowIconOnTitleBar="False" TitleCaps="True">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter" />
            <DataTemplate x:Key="FullCoverTemplate" >
                <Control>
                    <Control.Template>
                        <ControlTemplate>
                            <Border x:Name="bd" >
                                <Grid>
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Control.Template>
                </Control>
            </DataTemplate>
            <GroupStyle x:Key="groupStyle">
                <GroupStyle.ContainerStyle>
                    <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type GroupItem}">
                                    <ControlTemplate.Triggers>
                                        <DataTrigger Binding="{Binding Path=IsBottomLevel}" Value="True">
                                            <Setter TargetName="gridTemplate" Property="Grid.Background" Value="Black" />
                                        </DataTrigger>
                                    </ControlTemplate.Triggers>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <Grid Background="Black" x:Name="gridTemplate" Height="26" VerticalAlignment="Center">
                                            <Grid.Resources>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="FontSize" Value="14" />
                                                    <Setter Property="Foreground" Value="White" />
                                                    <Setter Property="VerticalAlignment" Value="Center" />
                                                </Style>
                                            </Grid.Resources>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="45" />
                                                <ColumnDefinition Width="50" />
                                            </Grid.ColumnDefinitions>

                                            <ToggleButton Grid.Column="0" x:Name="btnShowHide" IsChecked="False" Margin="3.5" />
                                            <TextBlock Grid.Column="1" Text="{Binding Path=Name}" Margin="3.5,0" />
                                            <TextBlock Grid.Column="2" Text="Count:" />
                                            <TextBlock Grid.Column="3" Text="{Binding Path=ItemCount}"  TextAlignment="Right" Margin="0,0,11,0" />

                                        </Grid>

                                        <ItemsPresenter Visibility="{Binding ElementName=btnShowHide, Path=IsChecked, Converter={StaticResource booleanToVisibilityConverter}}"
                                        Grid.Row="1" Margin="11,0,0,3.5" />

                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </GroupStyle.ContainerStyle>
            </GroupStyle>
            <!--Donate Button-->
            <Style x:Key="DonateButton" TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Border Name="Bd"  
                            Background="Transparent"  
                            BorderBrush="{TemplateBinding BorderBrush}"  
                            BorderThickness="0"  
                            Padding="{TemplateBinding Padding}"  
                            SnapsToDevicePixels="true">
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"  
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"  
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="true">
                                    <Setter TargetName="Bd" Property="BorderBrush" Value="Transparent"/>
                                    <Setter TargetName="Bd" Property="Background"  Value="Transparent"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Height" Value="30"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="BorderBrush" Value="{DynamicResource MouseOverColor}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </Window.Resources>
    <Controls:MetroWindow.WindowCommands>
        <Controls:WindowCommands>
            <Button ToolTip="Donate" Click="cmdDonate_Click" Height="30"
               Style="{StaticResource DonateButton}" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Image Source="..\Images\Donate.png" />
            </Button>
            <Button Content="Select Backup" Click="SelectBackup_Click" ToolTip="C:\Users\[USER]\AppData\Roaming\Apple Computer\MobileSync\Backup"/>
        </Controls:WindowCommands>
    </Controls:MetroWindow.WindowCommands>
    <Controls:MetroContentControl>
        <Grid>
            <Controls:ProgressRing IsActive="{Binding IsActive}" Name="progressRing" />
            <TabControl>
                <TabItem Header="Details" Name="tabDetails">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>

                        <Label Content="Device Name " VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="0" FontWeight="Bold"/>
                        <Label VerticalAlignment="Top" HorizontalAlignment="Right" Content="{Binding DisplayName}" Grid.Column="1" Grid.Row="0"/>

                        <Label Content="Phone Number " VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="1" FontWeight="Bold"/>
                        <Label VerticalAlignment="Top" HorizontalAlignment="Right" Content="{Binding PhoneNumber}" Grid.Column="1" Grid.Row="1"/>

                        <Label Content="Device Type " VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="2" FontWeight="Bold"/>
                        <Label VerticalAlignment="Top" HorizontalAlignment="Right" Content="{Binding ProductType}" Grid.Column="1" Grid.Row="2"/>

                        <Label Content="iOS Version " VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="3" FontWeight="Bold"/>
                        <Label VerticalAlignment="Top" HorizontalAlignment="Right" Content="{Binding iOS}" Grid.Column="1" Grid.Row="3"/>

                        <Label Content="Last Backup " VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="4" FontWeight="Bold"/>
                        <Label VerticalAlignment="Top" HorizontalAlignment="Right" Content="{Binding LastBackup}" Grid.Column="1" Grid.Row="4"/>

                    </Grid>
                </TabItem>
                <TabItem Header="Contact">
                    <ScrollViewer VerticalScrollBarVisibility="Auto">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <ItemsControl x:Name="TopLevelContact" ItemsSource="{Binding}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Vertical"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Expander ExpandDirection="Down">
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock>
                                                        <TextBlock.Text>
                                                            <MultiBinding StringFormat="{}{0} {1} {2}">
                                                                <Binding Path="First"/>
                                                                <Binding Path="Last"/>
                                                                <Binding Path="Organization"/>
                                                            </MultiBinding>
                                                        </TextBlock.Text>
                                                    </TextBlock>
                                                </StackPanel>
                                            </Expander.Header>
                                            <ListBox Name="NumberList" ItemsSource="{Binding Path=ABMultiValue5}">
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel Orientation="Horizontal">
                                                            <Label Content="{Binding Path=LongLabel}" FontWeight="Bold" VerticalAlignment="Center"/>
                                                            <TextBlock Text="{Binding Path=value}" TextWrapping="Wrap" VerticalAlignment="Center" />
                                                            <TextBlock Text="{Binding Path=PostalAdress}" TextWrapping="Wrap" VerticalAlignment="Center" />
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </Expander>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Grid>
                    </ScrollViewer>
                </TabItem>
                <TabItem Header="Sms">
                    <ScrollViewer VerticalScrollBarVisibility="Auto">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <ItemsControl x:Name="TopLevel" ItemsSource="{Binding}" >
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Vertical"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Expander ExpandDirection="Down">
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="{Binding Path=Info}"/>
                                                </StackPanel>
                                            </Expander.Header>
                                            <ListBox Name="SmsList" ItemsSource="{Binding Path=Items}" Grid.Row="1">
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel Orientation="Vertical">
                                                            <Label Content="{Binding Path=Date}" FontWeight="Bold"/>
                                                            <TextBlock Text="{Binding Path=text}" TextWrapping="Wrap" Background="#DDDDDD"  
                                                                       Width="400" Name="smsText" HorizontalAlignment="Left"/>
                                                        </StackPanel>
                                                        <DataTemplate.Triggers>
                                                            <DataTrigger Binding="{Binding Path=flags}" Value="3">
                                                                <Setter TargetName="smsText" Property="HorizontalAlignment" Value="Right" />
                                                                <Setter TargetName="smsText" Property="Background" Value="#C7E0FE" />
                                                            </DataTrigger>
                                                        </DataTemplate.Triggers>
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </Expander>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Grid>
                    </ScrollViewer>
                </TabItem>
                <TabItem Header="Calls">
                    <ListBox Name="CallsList" ItemsSource="{Binding}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="Black" BorderThickness="0,0,0,2" Background="AliceBlue" >
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition></RowDefinition>
                                            <RowDefinition></RowDefinition>
                                        </Grid.RowDefinitions>
                                        <StackPanel Orientation="Horizontal" Grid.Row="0">
                                            <Label Content="{Binding Path=FullName}" FontWeight="Bold"/>
                                            <Label Content="{Binding Path=LongDate}"/>
                                            <Label Content="{Binding Path=LongDuration}" HorizontalAlignment="Right" Foreground="Blue"/>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal" Grid.Row="1">
                                            <Label Content="{Binding Path=address}" Foreground="Gray"/>
                                        </StackPanel>
                                    </Grid>
                                </Border>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </TabItem>
                <TabItem Header="Notes">
                    <ScrollViewer VerticalScrollBarVisibility="Auto">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <ItemsControl x:Name="TopLevelNotes" ItemsSource="{Binding}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Vertical"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Expander ExpandDirection="Down">
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="{Binding Path=ZNote.ZTITLE}" FontWeight="Bold" TextWrapping="Wrap"/>
                                                </StackPanel>
                                            </Expander.Header>
                                            <TextBlock Text="{Binding Path=ZCONTENT}"  VerticalAlignment="Center" TextWrapping="Wrap"/>
                                        </Expander>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Grid>
                    </ScrollViewer>
                </TabItem>
                <TabItem>
                </TabItem>
            </TabControl>
        </Grid>
    </Controls:MetroContentControl>

</Controls:MetroWindow >

    
    